package 排序;

import java.util.Arrays;

/**
 * 选择排序
 * <p>
 * 1、
 * <p/>
 * User: zhaixiaolong Date:2024/3/14 13:48 ProjectName: algorithm Version:
 */
public class 选择排序 {

    public static void main(String[] args) {
        int[] array = {5, 3, 9, 6, 2, 8, 4};
        sortChoose(array);
        System.out.println(Arrays.toString(array));
    }


    /**
     * 选择排序
     *
     * @param array
     */
    public static void sortChoose(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < array.length; j++) {
                if (array[minIndex] > array[j]) {
                    minIndex = j;
                }
            }
            int temp = array[i];
            array[i] = array[minIndex];
            array[minIndex] = temp;
        }
    }

}
